#ifndef BASE_CTTHREADGROUP_H_
#define BASE_CTTHREADGROUP_H_
#include "ctRWLock.h"
#include "ct_thread.h"
#include <vector>
class ctThreadGroup : private ctNoncopyable
{
        public:
                struct Callback
                {
                        virtual void exec(ctThread *e)=0;
                        virtual ~Callback(){};
                };

                typedef std::vector<ctThread *> Container;

                ctThreadGroup();
                ~ctThreadGroup();
                void add(ctThread *thread);
                ctThread *getByIndex(const Container::size_type index);
                ctThread *operator[] (const Container::size_type index);
                void joinAll();
                void execAll(Callback &cb);

                const Container::size_type size()
                {
                        ctRWLock_scope_rdlock scope_rdlock(rw_lock_);
                        return vts_.size();
                }
        private:
                Container vts_;
                ctRWLock rw_lock_;
};

#endif //BASE_CTTHREADGROUP_H_
